package com.kuang.springcloud.controller;

import com.kuang.springcloud.pojo.Dept;
import com.kuang.springcloud.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DeptConsumerController {
    /*
    * 学习了Feign之后,发现可以不用RestTemplate这个类去调用远程服务了,故这里其实是删了RestTemplate的
    * Feign的作用可能就是调用远程服务的接口,从而实现调用远程服务
    * */

    @Qualifier("com.kuang.springcloud.service.DeptClientService")
    @Autowired
    private DeptClientService service; // 这个类就是springcloud-api中service中的接口,为什么能调到呢?因为pom引入了springcloud-api

    @RequestMapping("/consumer/dept/add")
    public boolean add(Dept dept) {
        return this.service.addDept(dept);
    }

    @RequestMapping("/consumer/dept/get/{id}")
    public Dept get(@PathVariable("id") Long id) {
        return this.service.queryById(id);
    }

    @RequestMapping("/consumer/dept/list")
    public List<Dept> list() {
        return this.service.queryAll();
    }
}
